package cn.platform.controller;

import cn.platform.entity.Activity;
import cn.platform.entity.SchAnnounce;
import cn.platform.request.ActivityQueryDTO;
import cn.platform.request.ActivityUpdateDTO;
import cn.platform.request.SchAnnounceQueryDTO;
import cn.platform.response.ActivityVO;
import cn.platform.response.PageResult;
import cn.platform.response.Result;
import cn.platform.response.SchAnnounceVO;
import cn.platform.service.ActivityService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/api/activities")
public class ActivityController {

    @Autowired
    private ActivityService activityService;

    /**
     * 实现分页条件查询操作
     * @param activityQueryDTO
     * @return
     * @author oyq
     */
    @GetMapping
    public Result page(ActivityQueryDTO activityQueryDTO){
        log.info("分页查询学生活动信息");
        PageResult<ActivityVO> pageResult = activityService.page(activityQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 查看活动详情
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result detail(@PathVariable String id){
        log.info("查看活动详情{}",id);
        ActivityVO activityVO = activityService.detail(id);
        return Result.success(activityVO);
    }

    /**
     * 更新活动
     * @param id
     * @param dto
     * @return
     * @author oyq
     */
    @PutMapping("/{id}")
    public Result update(@PathVariable String id, @RequestBody ActivityUpdateDTO dto){
        log.info("更新公告的ID{}，数据{}",id,dto);
        dto.setId(id);
        activityService.update(dto);
        return Result.success();
    }

    /**
     * 删除单条活动记录
     * @param id
     * @return
     * @author oyq
     */
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id){
        log.info("删除活动{}",id);
        activityService.delete(id);
        return Result.success();
    }

    /**
     * 批量删除活动
     * @param ids
     * @return
     * @author oyq
     */
    @PostMapping("/batch")
    public Result deleteBatch(@RequestBody List<Integer> ids){
        log.info("批量删除：{}",ids);
        activityService.deleteBatch(ids);
        return Result.success();
    }
}
